package manyToMany

import (
	"context"
	"errors"
	v1 "gf-example/api/relationalQuery/v1"
	"gf-example/internal/dao"
	"gf-example/internal/service"
)

type sManyToMany struct {
}

func New() *sManyToMany {

	return &sManyToMany{}
}

func init() {
	service.RegisterManyToMany(New())
}

func (s *sManyToMany) FindByManyToMany(ctx context.Context) (out *v1.ManyToManyRes, errs error) {
	out = &v1.ManyToManyRes{Content: make([]*v1.Boyfriend, 0)}
	err := dao.Boyfriend.Ctx(ctx).WithAll().Scan(&out.Content)
	if err != nil {
		return nil, errors.New("查询对多对数据库失败:" + err.Error())
	}
	return out, nil
}
